package com.ppt.android.base.utils

import android.os.CountDownTimer
import androidx.lifecycle.*

/**
 *
 * @author ZouJiaCai
 * @since 2023/3/28 13:53
 */
object TimerUtils {

    /**
     * 倒计时
     */
    abstract class SMSTimer (millisInFuture: Long, countDownInterval: Long,lifecycle: Lifecycle): CountDownTimer(millisInFuture, countDownInterval),
        DefaultLifecycleObserver  {

        init {
            lifecycle.addObserver(this)
        }

        abstract fun onSMSTFinish()
        abstract fun onSMSTTick(millisUntilFinished: Long)

        override fun onFinish() {
            onSMSTFinish()
        }

        override fun onTick(millisUntilFinished: Long) {
            onSMSTTick(millisUntilFinished)
        }

        override fun onDestroy(owner: LifecycleOwner) {
            super.onDestroy(owner)
            this.cancel()
        }

        fun onClose() {
            this.cancel()
        }
    }
}